package com.penghaisoft.microwms.base.web.data.service.impl;

import com.penghaisoft.microwms.base.web.data.service.IBaseDictionaryService;
import com.penghaisoft.microwms.base.web.dictionary.dao.BaseDictionaryMapper;
import com.penghaisoft.microwms.common.base.model.BaseDictionary;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 字典表service
 * @author luoteng
 * @date 2017年6月9日 下午5:47:04
 * @version 1.0
 */
@Service("baseDictionaryService")
public class BaseDictionaryServiceImpl extends BaseService implements
		IBaseDictionaryService {
	@Resource
	private BaseDictionaryMapper baseDictionaryMapper;

	/**
	 * 新增记录
	 * 
	 * @param baseDictionary
	 * @return
	 */
	@Override
	public Resp create(BaseDictionary baseDictionary) {
		baseDictionaryMapper.create(baseDictionary);
		return success();
	}
	
	@Override
	public Integer deleteByPrimaryKeys(String dicType){
		return baseDictionaryMapper.deleteByDicType(dicType);
	}

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @param baseResource
	 * @return
	 */
	@Override
	public Pager<BaseDictionary> findListByCondition(int page, int rows,
													 BaseDictionary condition) {
		Pager<BaseDictionary> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		List<BaseDictionary> records = baseDictionaryMapper.queryList(pager,
				condition);
		long size = baseDictionaryMapper.queryCount(condition);
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/**
	 * 查询单条
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public BaseDictionary findById(String id) {
		return baseDictionaryMapper.queryById(id);
	}

	/**
	 * 修改记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp update(BaseDictionary baseDictionary) {
		baseDictionaryMapper.updateBySelect(baseDictionary);
		return success();
	}

	/**
	 * 根据条件查询所有字典信息，支持模糊匹配
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public List<BaseDictionary> queryAllByCondition(
			BaseDictionary baseDictionary) {
		return baseDictionaryMapper.queryAllByCondition(baseDictionary);
	}

	/**
	 * @Title queryDicTypeByCondition
	 * @Description 查询满足条件的字典种类
	 * @author luoteng
	 * @date 2017年6月9日:下午3:35:42
	 * @param baseDictionary
	 * @return
	 */
	@Override
	public List<BaseDictionary> queryDicTypeByCondition(
			BaseDictionary baseDictionary) {
		return baseDictionaryMapper.queryDicTypeByCondition(baseDictionary);
	}
	
	/**
	 * @Title queryAccttingType
	 * @Description 查询盘点种类
	 * @param baseDictionary
	 * @return
	 */
	@Override
	public List<BaseDictionary> queryAccttingType(
			BaseDictionary baseDictionary) {
		return baseDictionaryMapper.queryAccttingType(baseDictionary);
	}

	@Override
	public List<BaseDictionary> queryAllByType(String type) {
		return baseDictionaryMapper.queryAllByType(type);
	}
}
